import { createApp } from 'vue'
import App from './App.vue'
import myrouter from "@/router"
import ElementPlus, {ElMessage} from "element-plus"
import "element-plus/dist/index.css"
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import AdminNav from "@/components/AdminNav.vue";
import FrontNav from "@/components/FrontNav.vue";
import doThis from "@/api/getData";
// import {defineConfig} from "@vue/cli-service";


const app = createApp(App)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.config.globalProperties.$checkLogin = ()=>{
    doThis.doGet("/user/checkLogin").then(res=>{
        if (res.code !== '0'){
            localStorage.removeItem('token')
            localStorage.removeItem('user')
            // alert("登录失效，请重新登录")
            ElMessage.error('登录失效，请重新登录')
            location.replace('http://localhost:8080/#/login')
        }
    })
}

/*
module.exports = defineConfig({
    transpileDependencies: true,
    devServer:{
        proxy:{
            'localhost:8081/gaode':{                     //这个就是的标识，当接口用 localhost 开头才用代理
                target:'https://restapi.amap.com/v3/geocode/regeo',       //这是代理到哪里
                // pathRewrite:{ '^/localhost':''}, //这个是路径重写，比如代理的标识是 localhost，但是要请求的路径里没有 localhost 这个字符串，所以用pathRwrite把  localhost  换成空字符串，也就是删掉，之后再拼到target上就合适了
                changeOrigin:true                //开启代理：在本地会创建一个虚拟服务端，然后发送请求的数据，并同时接收请求的数据，这样服务端和服务端进行数据的交互就不会有跨域问题
            }
        }
    }
})
*/

// 屏蔽错误信息
app.config.errorHandler = () => null;
// 屏蔽警告信息
app.config.warnHandler = () => null;

app.use(myrouter).use(ElementPlus).use(AdminNav).use(FrontNav)
    .mount('#app')
